home *** CD-ROM | disk | FTP | other *** search
- /*
- This file contains all the code needed to handle dispatching events.
- Any files that need to access the globals should include the Event.h file.
- */
-
- #include "Event.h"
- #include <AppleEvents.h>
- #include "NotificationMon.h"
-
- Boolean Done = false;
- Boolean KeyPressed = false;
- char KeyValue = 0;
- Boolean InBackGround = false;
-
- void DoCloseWindow(EventRecord *Event, WindowPtr theWindow)
- {
- if(TrackGoAway(theWindow,Event->where))
- {
- CloseWindow(theWindow);
- }
- }
-
- void DoClickInContent(EventRecord *Event, WindowPtr theWindow)
- {
- int part;
- ControlHandle ctlh;
- Point pt;
- GrafPtr saveport;
- Rect frame;
-
- if(theWindow!=FrontWindow())
- {
- SelectWindow(theWindow);
- }
- else
- {
- GetPort(&saveport);
- SetPort(theWindow);
- if(IsNotificationDoc(theWindow))
- NotificationClick(theWindow, Event);
- SetPort(saveport);
- }
- }
-
-
-
-
- void DoDragWindow(register EventRecord *Event, register WindowPtr theWindow)
- {
- DragWindow(theWindow,Event->where,&screenBits.bounds);
- }
-
-
- void DoGrowWindow(register EventRecord *Event, register WindowPtr theWindow)
- {
- long newSize;
- int newHeight,newWidth;
- GrafPtr savePort;
-
- if(IsNotificationDoc(theWindow))
- SizeNotificationWindow(theWindow,Event);
- else {
- GetPort(&savePort);
- SetPort(theWindow);
- newSize = GrowWindow(theWindow,Event->where,&screenBits.bounds);
- newHeight = HiWord(newSize);
- newWidth = LoWord(newSize);
- SizeWindow(theWindow,newWidth,newHeight,true);
- SetPort(savePort);
- }
- }
-
- DoZoom(register EventRecord *Event, register WindowPtr theWindow, int part)
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theWindow);
-
- if(TrackBox(theWindow,Event->where,part))
- {
- if(IsNotificationDoc(theWindow))
- ZoomNotificationWindow(theWindow, part);
- else
- ZoomWindow(theWindow,part,true);
- }
-
- SetPort(savePort);
- }
-
-
-
- void DoMenu(register long msel)
- {
- int item,menu;
- item = LoWord(msel);
- menu = HiWord(msel);
- MenuDispatch(menu, item);
- HiliteMenu(0); /* remove menu title hiliting */
- }
-
- DoKey(EventRecord *Event)
- {
- char c;
-
- c = (char)Event->message & charCodeMask;
-
- if((Event->modifiers & cmdKey) == FALSE)
- {
- KeyPressed = true;
- KeyValue = c;
- }
- else
- {
- DoMenu(MenuKey(Event->message & charCodeMask));
- }
- }
-
- void DrawVerticalGrowIcon(WindowPtr theWindow)
- {
- Rect clip;
-
- clip = theWindow->portRect;
- clip.left = clip.right - 15;
- clip.top = clip.bottom - 15;
- ClipRect(&clip);
-
- DrawGrowIcon(theWindow);
- ClipRect(&theWindow->portRect);
- }
-
- void DoUpdate(register EventRecord *Event)
- {
- WindowPtr theWindow;
- GrafPtr savePort;
-
- GetPort(&savePort); /* save current port */
-
- theWindow=(WindowPtr)Event->message; /* get windowPtr from event msg */
- SetPort(theWindow);
- ClipRect(&theWindow->portRect);
- BeginUpdate(theWindow);
- EraseRect(&theWindow->portRect); /* erase content region */
-
- DrawControls(theWindow); /* draw any controls in the window */
- DrawVerticalGrowIcon(theWindow);
-
- DrawImage(theWindow); /* sample routine to draw contents */
-
-
- EndUpdate(theWindow);
-
- SetPort(savePort);
- }
-
-
-
- void DoActivate(EventRecord *Event)
- {
-
- if(Event->modifiers & activeFlag)
- if(IsNotificationDoc((WindowPeek)Event->message))
- ActivateNotificationWindow(Event->message);
- else
- if(IsNotificationDoc((WindowPeek)Event->message))
- DeactivateNotificationWindow(Event->message);
- }
-
- void DoMFinder(register EventRecord *Event)
- {
- if( (Event->message >> 24) == suspendResumeMessage) {
- InBackGround = !(Event->message & resumeFlag);
- NotificationDocLayerSwitch();
- }
- }
-
- void DoClick(EventRecord *Event)
- {
- WindowPtr theWindow;
- switch(FindWindow(Event->where, &theWindow))
- {
- case inDesk: break;
- case inMenuBar: DoMenu(MenuSelect(Event->where));
- break;
- case inSysWindow: SystemClick(Event,theWindow);
- break;
- case inContent: DoClickInContent(Event,theWindow);
- break;
- case inDrag: DoDragWindow(Event,theWindow);
- break;
- case inGrow: DoGrowWindow(Event,theWindow);
- break;
- case inGoAway: DoCloseWindow(Event,theWindow);
- break;
- case inZoomIn: DoZoom(Event,theWindow,inZoomIn);
- break;
- case inZoomOut: DoZoom(Event,theWindow,inZoomOut);
- break;
- }
- }
-
-
-
- void MainEvent(void)
- {
- EventRecord Event;
- Boolean anEvent;
-
- KeyPressed = false; /* set to false every time through */
-
- anEvent = WaitNextEvent(everyEvent,&Event,GetSleepTime(),nil);
-
- if(anEvent)
- {
- switch(Event.what)
- {
- case nullEvent: CheckNotifications(); break;
- case mouseDown: DoClick(&Event); break;
- case mouseUp: break;
- case keyDown: DoKey(&Event); break;
- case keyUp: break;
- case autoKey: DoKey(&Event); break;
- case updateEvt: DoUpdate(&Event); break;
- case diskEvt: break;
- case activateEvt: DoActivate(&Event); break;
- case networkEvt: break;
- case driverEvt: break;
- case app1Evt: break;
- case app2Evt: break;
- case app3Evt: break;
- case osEvt: DoMFinder(&Event); break;
- case kHighLevelEvent: DoHighLevelEvent(&Event); break;
- }
- }
- else
- CheckNotifications();
- }
-
-
-